#/bin/bash
apt list --installed | grep davfs2
if [[ $? -eq 1 ]]
then
  sudo apt -y install davfs2
fi
if [[ ! -d ${HOME}/webdav ]]
then
  mkdir -p ${HOME}/webdav
fi
ls -1 ${HOME}/webdav | grep "lost+found"
if [[ $? -eq 0 ]]
then
  sudo umount ${HOME}/webdav
fi
sudo mount -t davfs http://localhost:5244/dav ${HOME}/webdav << EOF
admin
Qq15996779085
admin
Qq15996779085
EOF

webdavfs="http://localhost:5244/dav ${HOME}/webdav davfs _netdev,auto 0 0"
sudo cat /etc/fstab | grep "${webdavfs}"
if [[ $? -eq 1 ]]
then
  sudo sed -i '$a\'"${webdavfs}"'' /etc/fstab
fi
